<?php
/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 14/10/20
 * Time: 下午5:44
 */

class ModGoods {

    public static function indexData($params){
        $table = 'tblGameGoods';
        $where  = ' WHERE RecDate = :date AND Period = :period AND GameSrc=:game and ItemId != "ALL" ';
        $args   = array(
            ':date'     => $params['date'],
            ':period'   => "Daily",
            ':game'     => $params['g'],
        );
        
        $user = AccAuth::me();
        if($params['os'] != 'ALL' || $user['IsViewAll'] != 1){
        	$where .= " AND Platform=:p ";
        	$args[':p'] = $params['os'];
        }
        
        if($params['os'] == 'ALL' && $params['server'] == 'ALL'){  //都为all，查询专服下的所有渠道的服务器
        	$modServer = new ModServer();
        	$list = $modServer->getServerForSpecialId($params['g'],$params['special_id']);
        	$where .= " AND ( ";
        	foreach ($list as $key=>$val){
        		$where .= " SID = '{$val['develop_id']}'  or";
        	}
        	$where = substr($where, 0, -2);
        	$where .= " ) ";
        }else{
        	$where .= " AND SID=:ser ";
        	$args[':ser'] = empty($params['server']) ? 'ALL' : $params['server'];
        }

        $sql = "SELECT RecDate,SID,ItemId,ItemName,GetUser,GetNumber,GetCnt,UsedUser,UsedNumber,UsedCnt
                FROM {$table} {$where} order by RecDate desc, SID asc";

        $dbLink = new PubDbLink('dbSelf', PubDatabase::getMgmtDbName($params['p'], $params['g']));
        return $dbLink->query($sql, $args);
    }

}